import type { MultipleConditionSearchSchema } from '@/components/multiple-condition-search'
import { getApplicationsApi } from '@/apis/modules/application'

export default function useConfig() {
  const appList = ref<LabelValue[]>([])

  async function getApplications() {
    const res = await getApplicationsApi({ limit: 500 })
    appList.value = (res.list || []).map((item) => {
      return {
        label: item.name!,
        value: item.app_id!,
      }
    })
  }

  const searchSchema = computed<MultipleConditionSearchSchema>(() => {
    return {
      placeholder: '默认按照集群名称搜索',
      widgets: [
        {
          type: 'input',
          label: '集群名称',
          field: 'name_keyword',
          maxLength: 30,
        },
        // {
        //   type: 'input',
        //   label: '域名',
        //   field: 'domain_keyword',
        // },
      ],
    }
  })

  const tableColumns = buildColumns([
    {
      title: '区域名称',
      dataIndex: 'name',
    },
    {
      title: '备注',
      dataIndex: 'remark',
      slotName: 'remark',
    },
    {
      title: '创建时间',
      dataIndex: 'created_at',
      format: 'date-time',
      sortable: sortableSettings,
    },
    // {
    //   title: '操作',
    //   width: 116,
    //   slotName: 'action',
    //   cellClass: 'actions-cell',
    // },
    {
      title: '操作',
      fixed: 'right',
      slotName: 'actions',
      width: 80,
      cellClass: 'actions-cell',
    },
  ])

  onMounted(getApplications)

  return {
    searchSchema,
    tableColumns,
  }
}
